package com.hongxun.budget.ui.fragment.sg;

import android.widget.EditText;

import com.hongxun.budget.R;
import com.hongxun.budget.ui.fragment.BaseFragment;
import com.hongxun.budget.utils.SPUtils;
import com.hongxun.budget.utils.SgDBUtils;
import com.hongxun.budget.utils.SgStrKey;
import com.hongxun.greenentity.sg.CPolePitEntity;

import java.util.Date;

import butterknife.BindView;

/**
 * 隐蔽工程信息详情：电杆坑
 */
public class EditPolePitInfo extends BaseFragment {
    @BindView(R.id.et11)
    EditText et11;
    @BindView(R.id.et12)
    EditText et12;
    @BindView(R.id.et13)
    EditText et13;
    @BindView(R.id.et14)
    EditText et14;
    @BindView(R.id.et15)
    EditText et15;

    private CPolePitEntity polePitEntity;

    public EditPolePitInfo() {
    }

    @Override
    public int getLayoutId() {
        return R.layout.sg_fragment_editpolepitinfo;
    }

    @Override
    public void initView() {
        if (getArguments().getBoolean("isNewAdd", false)) {
            polePitEntity = new CPolePitEntity();
            polePitEntity.setGuid(String.valueOf(SPUtils.get(context, SgStrKey.uuidxx, "")));
            polePitEntity.setPGuid(String.valueOf(SPUtils.get(context, SgStrKey.uuidxm, "")));
            polePitEntity.setMCGuid(String.valueOf(SPUtils.get(context, SgStrKey.uuidjl, "")));
            polePitEntity.setPPDatastate("新增");
            polePitEntity.setPPResult("合格");
            //默认值
            et15.setText(polePitEntity.getPPResult());
        } else {
            polePitEntity = SgDBUtils.getCPolePit(String.valueOf(SPUtils.get(context, SgStrKey.uuidxx, "")));
            et11.setText(polePitEntity.getPPDesigndepth());
            et12.setText(polePitEntity.getPPActualdepth());
            et13.setText(polePitEntity.getPPSoil());
            et14.setText(polePitEntity.getPPStone());
            et15.setText(polePitEntity.getPPResult());
        }
    }

    //保存
    public void saveData(String name) {
        String trim11 = et11.getText().toString().trim();//设计坑深
        String trim12 = et12.getText().toString().trim();//实测坑深
        String trim13 = et13.getText().toString().trim();//土层深度
        String trim14 = et14.getText().toString().trim();//砂石深度
        String trim15 = et15.getText().toString().trim();
        polePitEntity.setMCName(name);
        polePitEntity.setPPDesigndepth(trim11);
        polePitEntity.setPPActualdepth(trim12);
        polePitEntity.setPPSoil(trim13);
        polePitEntity.setPPStone(trim14);
        polePitEntity.setPPResult(trim15);
        polePitEntity.setPPAddtime(new Date(System.currentTimeMillis()));
        SgDBUtils.upDataCPolePitEntity(polePitEntity);
    }
}
